package com.ot.flink.cdc.biz.controller;

import com.ot.flink.cdc.biz.domain.CdcTask;
import com.ot.flink.cdc.biz.dto.R;
import com.ot.flink.cdc.biz.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 首页
 * @author: pangtt
 * @date: 2023/9/24
 * @since JDK1.8 version: 1.0.0
 */
@Controller
public class IndexController {

    @Autowired
    private TaskService taskService;

    @RequestMapping("/")
    public ModelAndView index(ModelAndView model){
        model.addObject("taskList", this.taskService.getAllTask());
        model.setViewName("index");
        return model;
    }

    @PostMapping("/updateTask")
    @ResponseBody
    public R<?> index(@RequestBody CdcTask params){
        this.taskService.stopOrStartTask(params);
        return R.of("ok");
    }

}
